#include <winsock2.h>
#include <windows.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <iostream>
#include "Globals.h"

#pragma comment(lib, "Ws2_32.lib")

#ifndef NET_LISTENER_H
#define NET_LISTENER_H

#define PORT 5001     //The port the server is listening on
class CommandHandler;
DWORD WINAPI SocketHandler(void*);


class NetListener{

public:
	NetListener(CommandHandler *commandHandler);
	~NetListener(void);
	void startListening();

private:
	CommandHandler *commandHandler;
	int host_port;


	//Initialize socket support WINDOWS ONLY!
    unsigned short wVersionRequested;
    WSADATA wsaData;
    int err;
	struct sockaddr_in my_addr; //Listening to my_addr

    int* csock;
    sockaddr_in sadr;
    int addr_size;

	//Start read ip address
	 WORD wVersionRequestedIp;
     WSADATA wsaDataIp;
     char name[255];
     char *ip;
     PHOSTENT hostinfo;
     //End read ip address

};

struct SocketHandlingStruct{
	int *csock;
	CommandHandler *commandHandler;
};
#endif